package org.sakai.config;

import org.sakai.config.interceptors.UserLoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcInterceptorsConfig implements WebMvcConfigurer {
    /**
     * 添加拦截器
     * @param registry
     */
    @Autowired
    UserLoginInterceptor userLoginInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册TestInterceptor拦截器
        InterceptorRegistration registration = registry.addInterceptor(userLoginInterceptor);
        //所有路径都被拦截
        registration.addPathPatterns("/**");
        //添加不拦截路径
        registration.excludePathPatterns(
                "/user/login",
                "/user/register",
                "/user/sendEmailCode/**",
                "/user/images/**",
                "/public/images/**",
                "/pay/**",
                "/**/*.html",
                "/**/*.js",
                "/**/*.css",
                "/socket.io/**",
                "/consult/images/**"
        );
    }
}
